package router

import (
	v1 "chat/api/v1"
	"chat/config"
	"chat/internal/middleware"
	"github.com/gin-gonic/gin"
	"net/http"
)

func GetRouter() *gin.Engine {
	gin.SetMode(config.GetConfig().Server.RunMode)
	r := gin.New()

	// 添加gin拦截器
	r.Use(middleware.Cors()).Use(gin.Recovery())

	r.GET("/chat", Chat)
	r.GET("/test", v1.Test)
	r.POST("/user/login", v1.Login)
	r.GET("/user", v1.GetUserInfo)
	r.GET("/user/friend", v1.GetFriendIdList)
	r.GET("/user/friend/info", v1.GetLinkedInfoList)
	r.GET("/user/friend/message/all", v1.GetMessages)
	r.GET("/user/message/all", v1.GetAllMessagesByUId)
	r.GET("/user/friend/all", v1.GetUserFriendByUId)
	r.POST("/user/friend", v1.CreateRelation)
	r.POST("/user", v1.UpdateUserInfo)
	r.GET("/group", v1.GetAllGroup)
	r.POST("/group", v1.CreateGroup)
	r.GET("/groupMember", v1.GetAllGroupMember)
	r.POST("/user/sign", v1.SignUp)
	r.GET("/user/chat/list", v1.GetChatUserListByUserId)
	r.GET("/group/info", v1.GetGroupInfoByGroupId)
	r.POST("/user/group/join", v1.JoinGroup)
	r.POST("/upload/avatar", v1.UploadAvatar)
	r.POST("/group/name", v1.UpdateGroupName)
	r.POST("/group/notice", v1.UpdateGroupNotice)
	// 静态文件服务
	r.StaticFS("/image", http.Dir("./image"))

	return r
}
